package net.jlnx.Uebung4_1.util;

import java.util.Vector;

import net.jlnx.Uebung4_1.data.Figur;

public class FigurenHelper {
	public static double gesamtFlaeche = 0;

	public static void bubbleSort(Object[] xs) {
		boolean unsorted = true;
		while (unsorted) {
			unsorted = false;
			for (int i = 0; i < xs.length - 1; i++) {
				if (!(((Figur) xs[i]).getZIndex() <= ((Figur) xs[i + 1])
						.getZIndex())) {
					Figur dummy = (Figur) xs[i];
					xs[i] = xs[i + 1];
					xs[i + 1] = dummy;
					unsorted = true;
				}
			}
		}
	}

	public static void getGesamtFlaecheZIndex(int fromZ, int toZ, Object[] tmp) {
		Vector<Figur> tmp2 = Figur.filterZ(fromZ, toZ, tmp);
		for (Figur figur : tmp2) {
			FigurenHelper.gesamtFlaeche += figur.getElementFlaeche();
		}

		System.out.println("Die Gesamtfläche aller " + tmp2.size()
				+ " Figuren beträgt " + gesamtFlaeche + " Flächeneinheiten.");
		System.out.println("Die durchschnittliche Fläche pro Figur beträgt "
				+ gesamtFlaeche / tmp2.size() + " Flächeneinheiten.");
	}

}